package com.zhaojk.audio.mapper;

import com.zhaojk.audio.domain.DTO.WordDefinition;
import com.zhaojk.audio.entity.Scene;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author zhaojk
 */
@Mapper
public interface SceneMapper {
    @Select("SELECT sd.def_id FROM scene s, scene_definition sd WHERE s.sce_id = #{id}::uuid and s.sce_id = sd.sce_id")
    List<String> findDefsBySceneId(String id);

    /**
     * 动态IN查询方法
     *
     * @param ids
     * @return
     */
    @Select("<script>" +
            "SELECT word.word as lemma, " +
            "       definition.pos, " +
            "       word.level as audioLevel, " +
            "       definition.meaning as translation " +
            "FROM word " +
            "JOIN definition ON word.word_id = definition.word_id " +
            "WHERE def_id IN " +
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>" +
            "   #{id}::uuid" +
            "</foreach>" +
            "</script>")
    List<WordDefinition> findWordsByDefIds(@Param("ids") List<String> ids);
}
